package com.zqxq.lottery.api.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 苦智
 * @date 2018/10/27 15:05
 * @description 全局异常处理
 * @ClassName GlobalExceptionHandler
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler
    @ResponseBody //在返回自定义相应类的情况下必须有，这是@ControllerAdvice注解的规定
    public Map<String,Object> exceptionHandler(Exception e, HttpServletResponse response){
        log.info("服务器异常",e);
        Map<String,Object> map = new HashMap();
        map.put("code",500);
        map.put("msg","网络繁忙，请稍后重试");
        return map;
    }
}
